import request from '@/utils/request';

// 查询收件箱邮件列表
export async function getInmails(params) {
    return request('/api/mail/v1/inbox/inmailspage', {
        method: 'POST',
        data: params
    });
}

// 查询发件箱邮件列表
export async function getSentmails(params) {
    return request('/api/mail/v1/inbox/sentmailspage', {
        method: 'POST',
        data: params
    });
}

// 获取员工头像和姓名
export async function getImage(params) {
    return request(`/api/oa/v1/my/email/employee/avatar/list?emailList=${params.join('&emailList=')}`, {
        method: 'GET'
    });
}

// 模糊查询员工邮箱
export async function searchMailList(params) {
    return request('/api/org/v1/employeeInfo/simpleInfo/list', {
        method: 'POST',
        data: { name: params.name }
    });
}

// 通过邮件ID获取邮件详情
export async function fetchMailInfo(mailId) {
    return request(`/api/mail/v1/inbox/getmailbyid?mailId=${mailId}`, {
        method: 'GET'
    });
}

// 邮件下载
export async function fileDownload(params) {
    return request('/api/mail/v1/mail/attach/download', {
        method: 'POST',
        data: params,
        getResponse: true,
        encryption: false,
        isFile: true,
        responseType: 'blob',
        headers: { 'Content-Type': 'application/json' }
    });
}

// 邮件拉取
export async function fetchPullList(params) {
    return request('/api/mail/v1/mail/refresh', {
        method: 'POST',
        data: params
    });
}

// 邮件标记为已读
export async function setMailRead(params) {
    return request('/api/mail/v1/inbox/read', {
        method: 'PUT',
        data: params
    });
}

// 邮箱绑定
export async function fetchMailBind(params) {
    return request('/api/mail/v1/user/bind/mailbind', {
        method: 'POST',
        data: params
    });
}

// 邮件删除
export async function deleteMail(params) {
    return request('/api/mail/v1/inbox/delete', {
        method: 'POST',
        data: params
    });
}

// 获取授权邮件跳转链接地址
export async function mialLinkAdd(params) {
    return request('/api/user/v1/oa/bind/email/send', {
        method: 'GET',
        data: params
    });
}

// 根据路径key获取到登录者邮箱名字
export async function getMailName(params) {
    return request(`/api/user/v1/oa/email/get/${params.key}`, {
        method: 'GET'
    });
}

// 获取邮箱提示信息
export async function fetchMailPrompt(params) {
    const { userCode } = params;
    return request(`/api/mail/v1/inbox/getmailprompt${userCode ? `?userCode=${userCode}` : ''}`, {
        method: 'GET'
    });
}

// 获取用户绑定信息
export async function fetchMailBindInfo(params) {
    return request('/api/mail/v1/user/bind/getbindinfo', {
        method: 'POST',
        data: params
    });
}

// 获取已配置的可绑定邮箱列表
export async function fetchMailBindTemplates() {
    return request('/api/mail/v1/user/bind/bindtemplates', {
        method: 'GET'
    });
}

// 单个邮箱解绑
export async function fetchMailUnbind(params) {
    return request('/api/mail/v1/user/bind/unbind', {
        method: 'POST',
        data: params
    });
}

// 设置主邮箱
export async function fetchSetMainMail(params) {
    return request('/api/mail/v1/user/bind/setmainmail', {
        method: 'POST',
        data: params
    });
}

// 用户邮箱绑定信息编辑
export async function fetchMailUpdateBind(params) {
    return request('/api/mail/v1/user/bind/updatebind', {
        method: 'POST',
        data: params
    });
}
